package Demo4;

import java.util.concurrent.ThreadLocalRandom;

public class Main9 {
    public static void main(String[] args) throws InterruptedException {
        Object locker1=new Object();
        Object locker2=new Object();
        Object locker3=new Object();

     Thread a=new Thread(()->{
         synchronized (locker3){
             try {
                 locker3.wait();
             } catch (InterruptedException e) {
                 throw new RuntimeException(e);
             }
         }
         System.out.println(Thread.currentThread().getName());
     },"a");
        Thread b=new Thread(()->{
            synchronized (locker2){
                try {
                    locker2.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println(Thread.currentThread().getName());
            synchronized (locker3){
                locker3.notify();
            }
        },"b");
        Thread c=new Thread(()->{
            synchronized (locker1){
                try {
                    locker1.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println(Thread.currentThread().getName());
            synchronized (locker2){
                locker2.notify();
            }
        },"c");


        a.start();
b.start();
c.start();
Thread.sleep(1000);
synchronized (locker1){
    locker1.notify();
}
    }
}
